<template>
  <div class="app-container">
    <el-card style="border-radius: 10px">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="订单编号" prop="orderCode">
          <el-input
            v-model="queryParams.orderCode"
            placeholder="请输入订单编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="生产商名称" prop="manufactureName"label-width="90px">
          <el-input
            v-model="queryParams.manufactureName"
            placeholder="请输入生产商名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
      <el-row :gutter="10" class="mb8">

        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table border v-loading="loading" :data="orderList">
        <el-table-column label="订单编号" align="center" prop="orderCode" >
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleInfo(scope.row)">{{ scope.row.orderCode }}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="需求截至日期" align="center" prop="deadline" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.deadline, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="生产商编码" align="center" prop="manufactureCode" />
        <el-table-column label="生产商名称" align="center" prop="manufactureName" />
        <el-table-column label="联系人" align="center" prop="contact" />
        <el-table-column label="联系人电话" align="center" prop="contactTel" />
        <el-table-column label="付款类型" align="center" prop="paymentType" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.erp_payment_type" :value="scope.row.paymentType"/>
          </template>
        </el-table-column>

        <el-table-column label="成本" align="center" prop="estimatedCost" />
        <el-table-column fixed="right" label="操作" width="240px" align="center">
          <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-s-check"
                @click="handleGoApprove(scope.row)"
                v-hasPermi="['pro:outsourcingorder:approve']"
              >审核</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <ApproveView ref="infoView"></ApproveView>
  </div>
</template>

<script>
import {listApproveOrder} from "@/api/mes/pro/outsourcingorder";

import ApproveView from "@/views/mes/pro/outsourcingorder/approveView.vue";


export default {
  name: "outapprovelist",
  components: {
    ApproveView
  },
  dicts: ['erp_payment_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购计划表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: null,  deadline: null,        manufactureId: null,        manufactureCode: null,        manufactureName: null,    contact: null,        contactTel: null,        paymentType: null,        status: null  },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    formatCurrency(number) {
      return new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY' }).format(number);
    },
    /** 查询采购计划列表 */
    getList() {
      this.loading = true;
      listApproveOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 查看按钮操作 */
    handleInfo(row) {
      this.$refs.infoView.open = true;
      this.$refs.infoView.optType = 'view';
      this.$refs.infoView.title='订单详情'
      this.$refs.infoView.init(row.orderId);
    },
    handleGoApprove(row){
      this.$refs.infoView.open = true;
      this.$refs.infoView.title='订单审批'
      this.$refs.infoView.optType = 'confirm';
      this.$refs.infoView.init(row.orderId);
    }
  }
};
</script>
